<template>
	<view>
		<view class="main">
			<view class="else">
				<u-image width="200" height="200" :src="require('../../../static/image/icons.png')"></u-image>
				<text class="logo">酷疆</text>
				<u-button shape="circle" :ripple="true" ripple-bg-color="#8EB7FA" :custom-style="customStyle" @click="handleToLogin">
					<u-icon style="margin-right: 15rpx;" size="50" name="weixin-fill"></u-icon>
					立即登录
				</u-button>
				<view class="sub">
					<u-icon name=""></u-icon>
					勾选即表示同意
					<text @click="handleNavigateTo(1)">《用户协议》</text>
					及
					<text @click="handleNavigateTo(2)">《隐私条款》</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			navbarBackground: {
				backgroundImage: 'linear-gradient(90deg, rgb(27,52,92), rgb(49,84,142))'
			},
			customStyle: {
				width: '100%',
				backgroundColor: '#3d6fc1',
				color: '#f1f1f1',
				marginTop: '200rpx'
			}
		};
	},
	onLoad() {
		// #ifdef MP-WEIXIN
		uni.showShareMenu({
			withShareTicket: true,
			menus: ['shareAppMessage', 'shareTimeline']
		});
		// #endif
	},
	methods: {
		handleToLogin() {
			let that = this;
			uni.getProvider({
				service: 'oauth',
				success: function(res) {
					if (~res.provider.indexOf('weixin')) {
						uni.login({
							provider: 'weixin',
							success: function(loginRes) {
								let access_token = loginRes.authResult.access_token;
								uni.getUserInfo({
									provider: 'weixin',
									success: function(infoRes) {
										let info = infoRes.userInfo;
										let params = {
											access_token: access_token,
											openid: info.openId
										};
										that.$baseRequest('/api/Login/appLogin', params, 'POST').then(res => {
											uni.showToast({
												title: res.toString()
											});
											let token = res.data.token;
											uni.setStorageSync('tk', token);
											uni.setStorageSync('login_state', true);
											uni.switchTab({
												url: '../mine',
												success: function() {
													uni.showToast({
														title: '登录成功'
													});
												}
											});
										});
									}
								});
							}
						});
					}
				}
			});
		},
		handleNavigateTo(index) {
			if (index == 1) {
				uni.navigateTo({
					url: '../userAgreement/userAgreement'
				});
			} else {
				uni.navigateTo({
					url: '../privacyPolicy/privacyPolicy'
				});
			}
		}
	}
};
</script>

<style lang="scss" scoped>
.main {
	.else {
		padding: 20vh $uni-spacing-row-lg;
		display: flex;
		flex-direction: column;
		align-items: center;

		.logo {
			padding-top: 100rpx;
			font-size: 1.5rem;
			color: #3d6fc1;
		}

		.sub {
			display: flex;
			align-items: center;
			padding-top: 100rpx;

			text {
				color: #3d6fc1;
			}
		}
	}
}
</style>
